<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>case-vue-router</title>
    <link rel="stylesheet" href="./css/index.css">
    <script src="./lib/vue_2.5.22.js"></script>
    <script src="./lib/vue-router_3.0.2.js"></script>
</head>

<body>
    <div id="app">
        <router-view></router-view>
    </div>

    <script>
        const App = {
            template: `<div>
                <!-- header start -->
                <header class="header">传智后台管理系统</header>
                <!-- header end -->
                <!-- main start -->
                <div class="main">
                    <!-- lift start -->
                    <div class="left">
                        <ul>
                            <li><router-link to="/users">用户管理</router-link></li>
                            <li><router-link to="/rights">权限管理</router-link></li>
                            <li><router-link to="/goods">商品管理</router-link></li>
                            <li><router-link to="/orders">订单管理</router-link></li>
                            <li><router-link to="/settings">系统设置</router-link></li>
                        </ul>
                    </div>
                    <!-- lift end -->
                    <!-- right start -->
                    <div class="right">
                        <div class="main-content">
                            <router-view />
                            
                        </div>
                        <button @click="back">返回</button>
                    </div>
                    <!-- right end -->
                </div>
                <!-- main end -->
                <!-- footer start -->
                <footer class="footer">版权信息</footer>
                <!-- footer end -->
            </div>`,
            methods: {
                back: function () {
                    this.$router.go(-1)
                }
            }
        }
        const Users = {
            data: function () {
                return {
                    users: [
                        { id: 1, name: "张三", age: 18 },
                        { id: 2, name: "李四", age: 19 },
                        { id: 3, name: "王五", age: 20 },
                        { id: 4, name: "赵六", age: 21 },
                    ]
                }
            },
            template: `<div>
                <h4>用户管理区域</h4>
                <table>
                    <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>年龄</th>
                        <th>操作</th>
                    </tr>
                    <tr :key="item.id" v-for="(item, index) in users">
                        <td>{{item.id}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.age}}</td>
                        <td><a href="javascript:;" @click="detail(item.id)">详情</a></td>
                    </tr>
                </table>
            </div>`,
            methods: {
                detail: function (id) {
                    this.$router.push('/users/' + id)
                }
            }
        }
        const UsersInfo = {
            props: ['id'],
            template: `<div>
                <h4>用户详情----ID:{{id}}</h4>
            </div>`
        }
        const Rights = {
            template: `<div>
                <h4>权限管理区域</h4>
        </div>`
        }
        const Goods = {
            template: `<div>
                <h4>商品管理区域</h4>
        </div>`
        }
        const Orders = {
            template: `<div>
                <h4>订单管理区域</h4>
        </div>`
        }
        const Settings = {
            template: `<div>
                <h4>系统管理区域</h4>
        </div>`
        }
        const router = new VueRouter({
            routes: [
                { path: '/', redirect: '/users' },
                {
                    path: '/', component: App, children: [
                        { path: '/users', component: Users },
                        { path: '/users/:id', component: UsersInfo, props: true },
                        { path: '/rights', component: Rights },
                        { path: '/goods', component: Goods },
                        { path: '/orders', component: Orders },
                        { path: '/settings', component: Settings }
                    ]
                }
            ]
        })
        const vm = new Vue({
            el: '#app',
            router
        })
    </script>
</body>

</html>